﻿<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>密码修改</title>
<body>
<div class="container">
<div class="nav_header">
<?php
include 'conn.php';
include 'common.php';
include 'head.php';
?>
</div>
<div class="main_cj_content">	

<p class="welcome">请输入现有密码和新密码修改密码:</p>
<hr>

<br />
<br />
<fieldset>
<legend>修改密码</legend>
<form action="" method="post">
<table>
<tr>
<td><label>原密码：</label></td><td><input type="text" name="oldpasswd" id="oldpasswd" /></td></tr>
<tr><td><label>新密码：</label></td><td><input type="text" name="newpasswd" id="newpasswd"/></td></tr>

<tr><td><label>重复新密码：</label></td><td><input type="text" name="renewpasswd" id="renewpasswd"/></td></tr>

<tr><td><input type="submit" value="提交" onclick="return checkpasswd()"/></td><td></td></tr>
</table>
</form></fieldset>
<?php include 'foot.php';?>
</div>
</div>
</body>

<?php 
session_start();
$oldpasswd=getpost("oldpasswd");
$renewpasswd=getpost("renewpasswd");
$newpasswd=getpost("newpasswd");
if($oldpasswd&&$renewpasswd&&$newpasswd)
{
if($newpasswd!=$renewpasswd)
{
echo "<script language=javascript> alert('两次输入的密码不一致');</script>";
exit();
}
else
{
	$exe="select passwd from users where id=".$_SESSION['userid']."";
	echo $exe;
	$rs=mysql_query($exe);
	$row=mysql_fetch_array($rs);
	$truepasswd=$row['passwd'];
	echo $truepasswd;
	if(md5($oldpasswd)!=$truepasswd)
	{
		echo "<script language=javascript> alert('密码不正确!');</script>";
exit(); 
	}
	else 
	{
	
		$update="update users set passwd='".md5($newpasswd)."' where id=".$_SESSION['userid']."";
		$rs=mysql_query($update);
		if($rs)
			echo "<script language=javascript> alert('修改成功！');</script>";
		else
		{
			echo "<script language=javascript> alert('修改失败！请检查您的网络是否正常');</script>";
		exit;
		}
	
	
	}
}
}
else
{
//	echo "<script language=javascript> alert('请填写完整！');</script>";
	exit;
}

?>